package com.spring.boot;

import com.spring.core.env.Environment;
import com.spring.core.io.ResourceLoader;
import com.spring.logging.Log;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liyuncong
 * @version 1.0
 * @file SpringApplicationBannerPrinter
 * @brief SpringApplicationBannerPrinter
 * @details SpringApplicationBannerPrinter
 * @date 2023-01-12
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2023-01-12                  liyuncong          Created
 */
public class SpringApplicationBannerPrinter {

    private final ResourceLoader resourceLoader;

    private final Banner fallbackBanner;

    public SpringApplicationBannerPrinter(
        ResourceLoader resourceLoader, Banner fallbackBanner
    ) {
        this.resourceLoader = resourceLoader;
        this.fallbackBanner = fallbackBanner;
    }

    Banner print(Environment environment, Class<?> sourceClass, Log logger) {
        Banner banner = getBanner(environment);
        return banner;
    }

    Banner getBanner(Environment environment) {
        Banner banner = new Banners();
        return banner;
    }

    private static class Banners implements Banner {
        private final List<Banner> banners = new ArrayList<>();

        void addIfNotNull(Banner banner) {
            this.banners.add(banner);
        }

        boolean hasAtLeastOneBanner() {
            return !this.banners.isEmpty();
        }

        @Override
        public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
            for (Banner banner : this.banners) {
                banner.printBanner(environment, sourceClass, out);
            }
        }
    }
}
